home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl5
- #
- # security.cgi
- #
- # Copyright 1988-1996 Silicon Graphics, Inc.
- # All rights reserved.
- #
- # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- # the contents of this file may not be disclosed to third parties, copied or
- # duplicated in any form, in whole or in part, without the prior written
- # permission of Silicon Graphics, Inc.
- #
- # RESTRICTED RIGHTS LEGEND:
- # Use, duplication or disclosure by the Government is subject to restrictions
- # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- # rights reserved under the Copyright Laws of the United States.
- #
- # $Id: security.frm,v 1.5 1997/06/19 22:26:07 shotes Exp $
-
- require "/usr/OnRamp/lib/OnRamp.pm";
- require "/usr/OnRamp/lib/java.pm";
-
- $pid_file = "/usr/ns-home/admserv/pid";
- $start_ns_admin = "/usr/ns-home/start-admin > /dev/null 2>&1";
- $stop_ns_admin = "/usr/ns-home/stop-admin > /dev/null 2>&1";
-
- $title = "Netscape Admin Server Access Control";
- $myname = "security.cgi";
- $conf_file = "/usr/ns-home/admserv/ns-admin.conf";
- $pw_file = "/usr/ns-home/admserv/admpw";
- $dummy = "/usr/ns-home/admserv/ns-admin.conf.tmp";
-
- $account_type_lc = "account";
- $account_type_uc = "Account";
-
- $js_generic =
- "which = \"none\";
- type = \"account\";
- function runSubmit() {
- if(which == \"add\") return runAdd();
- if(which == \"edit\") return runEdit();
- if(which == \"delete\") return runDelete();
- return runDo();
- }
- function markAdd() { which = \"add\"; }
- function markEdit() { which = \"edit\"; }
- function markDelete() { which = \"delete\"; }
- $js_error_box
- $js_meta
- $js_ip
- $js_hostname
- function runEdit() {
- Ctrl = document.AccountForm.chosen
- none = true;
- for(j = 0; j < Ctrl.length; j++) {
- if (Ctrl.options[j].selected) { none = false; break; }
- }
- if (none) {
- errorBox (Ctrl, \"To edit an existing \" + type + \", \"
- + \"first select an \" + type + \"\\nfrom the list, \"
- + \"then click the edit button.\");
- return (false);
- }
- return (true);
- }
- function runDelete() {
- Ctrl = document.AccountForm.chosen;
- none = true;
- for(j = 0; j < Ctrl.length; j++) {
- if (Ctrl.options[j].selected) { none = false; break; }
- }
- if (none) {
- errorBox (Ctrl, \"To delete an existing \" + type + \", first \"
- + \"select an \" + type + \"\\nfrom the list, then click \"
- + \"the delete button.\");
- return (false);
- }
- return (true);
- }
- function runDo() {
- if (!testStarList(document.AccountForm.clients)) return (false);
- return (true);
- }
- function is_ip(word) {
- ipChars = \"0123456789\.*\";
- for (ii=0; ii<word.length; ii++) {
- c = word.charAt(ii);
- if (ipChars.indexOf(c, 0) == -1) {
- return (false);
- }
- }
- return (true);
- }
- function remove_star(word) {
- if (word.indexOf(\"*\", 0) == -1) return (word);
- new_word = \"\";
- for (jj = 0; jj < word.length; jj++) {
- if (word.charAt(jj) == \"*\")
- new_word = new_word + \"233\";
- else
- new_word = new_word + word.charAt(jj);
- }
- return (new_word);
- }
- function testStarList(Ctrl) {
- my_count = 0;
- ipChars = \"0123456789\.*\";
- whitespace = \" \\n\\r\\t\\f\"; space = true;
- for(start=0, cur=0; cur < Ctrl.value.length; cur++) {
- for(i = 0; i < whitespace.length; i++) {
- c = whitespace.charAt(i);
- if (Ctrl.value.charAt(cur) == c) { // found whitespace
- if (space == false) {
- space = true;
- if(cur != start) {
- host = Ctrl.value.substring(start,cur);
- my_count++;
- if (is_ip(host)) {
- new_host = remove_star(host);
- if (!testIPaddress(new_host,false)) {
- errorBox (Ctrl, \"Invalid server IP address: \" + host + \"\\nin server address list.\");
- return (false);
- }
- } else {
- if (!testHostname(Ctrl, host, \"hostname\", false)) return (false);
- }
- }
- }
- break;
- } else { // found character
- if (space == true) { space = false; start = cur; }
- }
- }
- }
- if(cur != start && space == false) {
- host = Ctrl.value.substring(start,cur);
- my_count++;
- if (is_ip(host)) {
- new_host = remove_star(host);
- if (!testIPaddress(new_host,false)) {
- errorBox (Ctrl, \"Invalid server IP address: \" + host + \"\\nin server address list.\");
- return (false);
- }
- } else {
- if (!testHostname(Ctrl, host, \"hostname\", false)) return (false);
- }
- }
- return (true);
- }
- function runAdd() {
- Ctrl = document.AccountForm.new_account;
- if (Ctrl.value.length == 0) {
- errorBox(Ctrl, \"To add a new $account_type_lc, first enter the new $account_type_lc name.\");
- return (false);
- }
- if (!testMeta(Ctrl, \"account name\")) return (false);
- return (true);
- }";
-
- $js_edit =
- "$js_standard
- $js_error_box
- $js_meta
- function checkForm(form) {
- if (form.uname.value.length == 0) {
- errorBox(form.uname, \"Account name cannot be empty.\");
- return (false);
- }
- if (form.password.value.length == 0) {
- errorBox(form.uname, \"Password cannot be empty.\");
- return (false);
- }
- if (!testMeta(form.uname, \"account name\")) return (false);
- if (!testMeta(form.password, \"password\")) return (false);
- return (true);
- }";
-
- print "Content-type: text/html\n\n";
-
- &get_fields;
- &get_accounts;
-
- if (%fld) {
- $fld{'chosen'} =~ /([\w.-]+)/; $chosen = $1;
-
- $help = $document_root . $ENV{"SCRIPT_NAME"};
- $help =~ s/cgi$/hlp/;
- exec $help if ($fld{'help'} eq "Help");
-
- if ($fld{'edit'}) {
- &get_edit($chosen);
- } elsif ($fld{'do_edit'}) {
- &generic;
- } elsif ($fld{'add'}) {
- &get_add;
- } elsif ($fld{'delete'}) {
- &generic($chosen);
- } elsif ($fld{'doit'}) {
- &do_it;
- &get_accounts;
- &generic;
- } elsif ($fld{'doedit'}) {
- &do_edit;
- &get_accounts;
- &generic;
- }
- } else { &generic; }
-
- sub do_it {
- &do_delete($fld{'deleted'}) if $fld{'deleted'};
- &process_clients;
- &bounce_server;
- }
-
- sub process_clients {
- @clients = split(/\s+/, $fld{'clients'});
- foreach (@clients) {
- if ($_ =~ /[^0-9\.\*]/) { push(@hosts, $_); }
- else { push(@adds, $_); }
- }
- if ($#hosts > 0) { $hosts = "(" . join('|', @hosts) . ")"; }
- elsif ($#hosts == 0) { $hosts = $hosts[0]; }
- else { $hosts = ""; }
-
- if ($#adds > 0) { $adds = "(" . join('|', @adds) . ")"; }
- elsif ($#adds == 0) { $adds = $adds[0]; }
- else { $adds = ""; }
-
- $hosts_added = 0;
- $adds_added = 0;
- open(IN, "< $conf_file");
- open(OUT, "> $dummy");
- while(<IN>) {
- if ($_ =~ /^Hosts\s/) {
- $hosts_added = 1;
- if ($hosts ne "") { print OUT "Hosts $hosts\n"; }
- } elsif ($_ =~ /^Addresses\s/) {
- $adds_added = 1;
- if ($adds ne "") { print OUT "Addresses $adds\n"; }
- } else { print OUT $_; }
- }
- if ($hosts ne "" && $hosts_added == 0) {
- print OUT "Hosts $hosts\n";
- }
- if ($adds ne "" && $adds_added == 0) {
- print OUT "Addresses $adds\n";
- }
-
- close(IN);
- close(OUT);
-
- rename($dummy, $conf_file);
-
- $message .= " Client list updated.";
- }
-
- sub bounce_server {
- open(IN, "< $pid_file");
- $pid = <IN>;
- close(IN);
- if ($pid) {
- system($stop_ns_admin);
- system($start_ns_admin);
- }
- }
-
- sub do_delete {
- open(IN, "< $pw_file");
- open(OUT, "> $dummy");
- while(<IN>) {
- print OUT $_ unless $_[0] eq (split(/:/, $_))[0];
- }
- close(IN);
- close(OUT);
-
- rename($dummy, $pw_file);
- &bounce_server;
-
- $message .= "$account_type_uc deleted.";
- }
-
- sub do_edit {
- $salt = &mksalt;
- $pswd = crypt($fld{'password'}, $salt);
- $line = $fld{'uname'} . ":" . $pswd;
-
- if ($fld{'old_account'} ne "") {
- open(IN, "< $pw_file");
- open(OUT, "> $dummy");
- while(<IN>) {
- if ($fld{'old_account'} eq (split(/:/, $_))[0]) {
- print OUT "$line\n";
- } else { print OUT $_; }
- }
- close(IN);
- close(OUT);
-
- rename($dummy, $pw_file);
-
- $message .= "$account_type_uc edited.";
- } else {
- open(OUT, ">> $pw_file");
- print OUT "$line\n";
- close(OUT);
-
- $message .= "$account_type_uc added.";
- }
-
- &bounce_server;
- }
-
- sub get_add {
- &get_edit($fld{'new_account'});
- }
-
- sub get_edit {
- &js_title_block($title, $js_edit);
- if ($fld{'add'}) { &header_block("Add $account_type_uc"); }
- else { &header_block("Edit $account_type_uc"); }
-
- print "<form name=StandardForm action=$myname method=post "
- . "onSubmit=\"return runSubmit()\">\n"
- . "<i>$message</i>\n"
- . "<center><br><table width=400>\n";
-
- if ($fld{'edit'}) {
- print "<input type=hidden name='old_account' value=$_[0]>\n";
- }
-
- print "<tr><th align=left>$account_type_uc name:<td>"
- . &text("uname", $_[0], 20)
- . "</td></tr>\n";
-
- print "<tr><th align=left>$account_type_uc password:<td>"
- . &text("password", $val{'password'}, 20)
- . "</td></tr>\n";
-
- print "</table></center><br>\n";
-
- print &js_buttons('doedit','Ok','onClick="markOK()"','onClick="markOther()"');
- }
-
- sub get_accounts {
- undef @accounts;
- open(IN, "< $pw_file");
- while(<IN>) {
- push(@accounts, (split(/:/, $_))[0]);
- }
- close(IN);
-
- undef @clients;
- open(IN, "< $conf_file");
- while(<IN>) {
- if ($_ =~ /^Hosts\s+(.*)/) {
- $list = $1;
- if ($list =~ /\((.*)\)/) {
- push(@clients, split(/\|/, $1));
- } else {
- push(@clients, $list);
- }
- } elsif ($_ =~ /^Addresses\s+(.*)/) {
- $list = $1;
- if ($list =~ /\((.*)\)/) {
- push(@clients, split(/\|/, $1));
- } else {
- push(@clients, $list);
- }
- }
- }
- close(IN);
- $val{'clients'} = join("\n", @clients);
- }
-
- sub generic {
- &js_title_block($title, $js_generic);
- &header_block($title);
-
- if ($_[0]) { $message .= qq|Click "Ok" to save changes.|; }
-
- print "<form name=AccountForm action=$myname method=post "
- . "onSubmit=\"return runSubmit()\">\n";
-
- print "<i>$message</i>\n"
- . "<br>\n"
- . "<h3>Allowed users:</h3><center><table width=400>\n"
- . "<tr><td><input type=submit name=\"add\" onClick=\"markAdd()\" \n"
- . "value=\"Add New $account_type_uc\"\n"
- . "</td><td><input name=\"new_account\" value=\"$val{'new_account'}\"\n"
- . "size=19 onClick=\"markAdd()\"></td></tr>\n";
-
- if ($#accounts >= 0) {
- if ($_[0]) {
- undef @show_accts;
- foreach $arg (@accounts) {
- push(@show_accts, $arg) if $arg ne $_[0];
- }
- print "<input type=hidden name=deleted value=$_[0]>\n";
- } else { @show_accts = @accounts; }
-
- print "<tr><td>\n"
- . "<input type=submit name=\"edit\" onClick=\"markEdit()\" \n"
- . "value=\"Edit Selected $account_type_uc\"></td><td rowspan=2>";
- print &choice_list(*show_accts, "chosen", 20);
- print "</td/tr>\n"
- . "<tr><td><input type=submit name=\"delete\" onClick=\"markDelete()\" \n"
- . "value=\"Delete Selected $account_type_uc\"></td></tr>\n";
- }
-
- print "</table></center><br>";
-
- print "<h3>Allowed clients:</h3>\n"
- . "<center>\n"
- . "<textarea name='clients' cols=20 rows=4>"
- . $val{'clients'}
- . "</textarea><br><br>\n";
-
- print &buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"');
- }
-
-
-